#ifndef CSOCKETCOMMUNICATION_H
#define CSOCKETCOMMUNICATION_H

#include <QObject>
#include <QMap>
#include <QTcpSocket>


class QString;


// Interfaces that acts as the base class of other working requester and responser.
class INetWorking;

class CSocketCommunication : public QObject
{
    Q_OBJECT

public:
    CSocketCommunication();
    ~CSocketCommunication();

public:
    // serverIP should be in the form like "127.0.0.1"
    void sendRequest(QString serverIP, unsigned short port, int command, void* para, int size);
    void stopRequest();

private Q_SLOTS:
    void hasConnected();
    void readyRead();
    void connectionClosedByServer();
    void error();

    ///////////////////////////////////
    void connectToServer(QString serverIP, unsigned short port);
    void closeConnection();

public:
    // this method can only be used in methods that is assigned to canRead() signal.
    QMap<QString, QString> getResult();
    QString getResult(QString name);

signals:
    // a signal that indicates we can try to read the data
    void canRead();
    void closeByServer();
    void socketError();

private:
    QTcpSocket      tcpSocket;
    INetWorking     *pNetWorking;
    int             nextBlockSize;

    void            *param;
    int             command;
};


#endif // CSOCKETCOMMUNICATION_H
